<?php
//任务中心首页
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
$return['set']=$this->plugin_setting('basic');
$return['setting']=$this->plugin_setting('basic');
if($_RQ['op']=='main'){
	//用户信息
	$return['member']=model('core/member')->detail($_SESSION['uid'],array('credit1','credit2','mobile','avatar','nickname'));
	$tableList = tablename('jy_inclock_task_list');
	$tableRecord = tablename('jy_inclock_task_record');
	$now = date('Y-m-d H:i:s');
	$sql = 'select li.*,re.task_demand,re.task_progress,re.id as rid from ' . $tableList . ' li left join ' . "\r\n" . '                (select *,max(id) from ' . $tableRecord . ' where (stoptime>\'' . $now . '\' or stoptime = \'0000-00-00 00:00:00\') and mid = \'' . $_SESSION['uid'] . '\' and finishtime = 0' . "\r\n" . '                group by taskid order by id desc) re on li.id = re.taskid ' . "\r\n" . '                where li.starttime < \'' . $now . '\' and li.endtime >\'' . $now . '\' and li.uniacid = :uniacid ' . "\r\n" . '                order by li.displayorder desc,li.id desc';
	$params = array(':uniacid' => $_SESSION['uniacid']);
	$return['list'] = pdo_fetchall($sql, $params);
	if($return['list']){
		foreach($return['list'] as &$li){
			$li['reward']=json_decode($li['reward'],true);
			$li['rewarddesc']='奖励';
			$reward=$li['reward'];
			$credit_types=credit_types();
			foreach($reward as $key=>$value){
					if(strpos($key,'credit') !== false && $value>0){
						$type=substr($key, -1);
						$li['rewarddesc'].='['.$value.$credit_types[$type].'] ';
					}
			}
		}
	}
	set_html('title',$return['setting']['title']?:'任务中心');
	$return['sharedata']=array(
		'title'=>$return['setting']['share_title']?'任务中心'.$return['setting']['share_title']:'任务中心',
		'desc'=>$return['setting']['share_desc']?$return['setting']['share_desc']:'任务中心！',
		'link'=>custom_url('jy_inclock/index//fromuser='.$_SESSION['uid'],true),
		'imgUrl'=>ATTACHMENT_URL.$setting['share_image']
	);
	exi($return);
}
